package com.shxzz.easy12306.services.user.service.handler.filter.user;

import com.shxzz.easy12306.framework.starter.convention.exceptions.ClientException;
import com.shxzz.easy12306.services.user.common.constant.UserRegisterConstant;
import com.shxzz.easy12306.services.user.dto.req.UserRegisterReqDTO;
import com.shxzz.easy12306.services.user.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 用户注销次数过多禁止注册
 * @author shxzz
 * @create 2024-02-28-21:19
 */
@RequiredArgsConstructor
@Component
public class UserRegisterDeletionNumChainHandler implements UserRegisterFilter{

    private final UserService userService;

    @Override
    public void handler(UserRegisterReqDTO requestParam) {
        Integer deletionNum =userService.queryUserDeletionNum(requestParam.getIdType(), requestParam.getIdCard());
        if(deletionNum >= UserRegisterConstant.MAXIMUM_USER_DELETION_NUM){
            throw new ClientException("用户多次注销，已加入黑名单");
        }
    }

    @Override
    public int getOrder() {
        return 200;
    }
}
